<template>
  <div v-loading="loading" class="app-container">
    <el-form ref="form" :rules="rules" :model="form">
      <el-divider content-position="left"><h3>机构配置</h3></el-divider>
      <el-form-item label="最大申报数量" :label-width="width" style="width: 600px" prop="institution.post_num">
        <el-input v-model="form.institution.post_num" placeholder="最多申报数量" autocomplete="off" clearable />
      </el-form-item>

      <el-divider content-position="left"><h3>评委设置</h3></el-divider>
      <el-form-item label="最大评审数量" :label-width="width" prop="review.review_num">
        <el-input v-model="form.review.review_num" placeholder="最大评审数量" autocomplete="off" clearable />
      </el-form-item>

      <el-form-item style="margin: auto">
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Config1Index',
  data() {
    return {
      loading: false,
      width: '180px',
      // 站点信息
      form: {
        institution: {
          post_num: ''
        },
        review: {
          review_num: ''
        },
        parent: 'news'
      },
      rules: {
        'institution.post_num': [
          { required: true, message: '请输入最大申报数量', trigger: 'blur' }
        ],
        'review.review_num': [
          { required: true, message: '请输入最大评审数量', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    const that = this
    this.loading = true
    this.$http.get('/newsDeclare/config1/news').then(response => {
      that.loading = false
      const basic = response.data
      Object.keys(basic).forEach(k => {
        Object.keys(basic[k]).forEach(key => {
          this.form[k][key] = basic[k][key]
        })
      })
    })
  },
  methods: {
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.$http.post('/newsDeclare/config1', this.form).then(response => {
            this.$message.success(response.message)
          })
        } else {
          console.log(valid)
        }
      })
    }
  }
}
</script>

<style scoped>
.el-form .el-form-item {
  width: 600px;
}
</style>
